package com.ewing.busi.stat.dao;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.ewing.busi.stat.model.StatAccessLog;
import com.ewing.core.jdbc.BaseDao;
import com.ewing.util.DataFormat;

/**
 * 访问统计日志DAO
 * 
 * @author tansonlam
 * @createDate 2016年4月20日
 * 
 */
@Repository("statAccessLogDao")
public class StatAccessLogDao {
    @Resource
    private BaseDao baseDao;

    /**
     * 获取昨日商店访问量
     * 
     * @param shopId
     * @return
     */
    public Integer getYesterdayAccessCount(Integer shopId) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -1);
        String nowDateStr = DataFormat.DateToString(cal.getTime(), DataFormat.DATE_FORMAT);
        String startDateStr = nowDateStr + " 00:00:00";
        String endDateStr = nowDateStr + " 23:59:59";
        String queryString = "  shop_id=" + shopId
                + " AND create_time BETWEEN  '" + startDateStr + "' AND '" + endDateStr
                + "' GROUP BY user_id,session_id";
        List<StatAccessLog> list = baseDao.find(queryString, StatAccessLog.class);
        return list.size();
    }
}
